package com.minyifang.wcspf.work.ui.home.presenter;

import com.minyifang.wcspf.common.base.BasePresenter;
import com.minyifang.wcspf.common.config.network.Constants;
import com.minyifang.wcspf.common.config.network.RetrofitHelper;
import com.minyifang.wcspf.common.config.user.UserManager;
import com.minyifang.wcspf.work.model.HttpRespond;
import com.minyifang.wcspf.work.ui.home.model.SplashBean;
import com.minyifang.wcspf.work.ui.home.view.MainView;

import org.json.JSONObject;

import io.reactivex.functions.Consumer;
import okhttp3.MediaType;
import okhttp3.RequestBody;

/**
 * Created by LuoYaWei on 2018/7/10.
 */
public class MainPresenter extends BasePresenter<MainView> {
    public void getSplashContent() {
        JSONObject jsonData = Constants.getJsonData(null, null);
        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), jsonData.toString());
        addTask(RetrofitHelper.getInstance().getService().getSplashContent(requestBody), getView()::showSplashContent);
    }

    public void checkVersion() {

        JSONObject jsonData = Constants.getJsonData(null, null);
        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), jsonData.toString());
        addTask(RetrofitHelper.getInstance().getService().checkVersion(requestBody), response -> getView().showVersionInfo(response));
    }

    public void getCarNum() {
        JSONObject jsonData = Constants.getJsonData(null, UserManager.getInstance().getToken());
        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), jsonData.toString());
        addTask(RetrofitHelper.getInstance().getService().getCarNum(requestBody), response -> getView().showCarNum(response));
    }
}
